<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>hello_react</title>
</head>
<body>
    <div id="test"></div>

    <!-- 引入 react 核心库 -->
    <script src="./js/react.development.js" type="text/javascript"></script>
    <script src="./js/react-dom.development.js" type="text/javascript"></script>
    <script src="./js/babel.min.js" type="text/javascript"></script>

    <script type="text/babel">
        class Weather extends React.Component {
            // 构造器调用 1 次
            constructor(props) {
                super(props)
                this.state = {
                    isHot : false
                }
                this.changeWeather = this.changeWeather.bind(this) // 需要使用bind改变changeWeather的指向we
            }
            // render 调用 1 + n 次，1为初始化， n为更新
            render() {
                const {isHot} = this.state
                return <h1 onClick={this.changeWeather}>今天天气很{isHot ? '炎热' : '凉爽'}</h1>
            }
            // 更新次数
            changeWeather() {
                const isHot = this.state.isHot
                this.setState({
                    isHot: !isHot
                })
            }
        }
        ReactDOM.render(<Weather/>, document.querySelector('#test'))
    </script>
</body>
</html>